<?php

if (!defined("EXPONENT")) exit("");global $db;

if (!isset($_REQUEST['ajax_action']) || ($_REQUEST['ajax_action'] != 1))
  exponent_flow_redirect();

// get the playlist
$playlist=$_REQUEST['playlist'];
$pl=$db->selectObject('present_playlist','session = "' . $playlist .'"');
if ($pl==null)
	exponent_flow_redirect();
else
{
	//update create_time
	$pl->create_time=time();
	$db->updateObject($pl,"present_playlist");
}
// get all songs
$sql="SELECT {$db->prefix}present_songs.* FROM {$db->prefix}present_songs INNER JOIN {$db->prefix}present_playlist_songs
		      ON {$db->prefix}present_songs.id = {$db->prefix}present_playlist_songs.song_id
		      WHERE {$db->prefix}present_playlist_songs.playlist_id = " . $pl->id . "
		      ORDER BY {$db->prefix}present_playlist_songs.rank";
$pl_songs=$db->selectObjectsBySql($sql);
// get all verse in each song
foreach ($pl_songs as $key=>$value)
{
	$s_verse=$db->selectObjects("present_song_verse","song_id = {$value->id} ORDER BY rank");
	// get background file
	foreach ($s_verse as $k=>$v)
	{
		// for background
		if ($v->background <= 0) {
			$v->picpath = '';
		} else {
			$file = $db->selectObject('file', 'id='.$v->background);
			$v->picpath = $file->directory.'/'.$file->filename;
		}
		$s_verse[$k]=$v;
	}
	// end of background file
	
	$value->verse=null; // reset first
	$value->verse=$s_verse;
	$pl_songs[$key]=$value;
}
$template = new template('slidemodule',"_presentation",$loc);
$template->assign("songs",$pl_songs);
$template->output();
?>
